import React, {Component} from 'react';
import {BaseEventOrig, ScrollView} from '@tarojs/components';
import {ScrollViewProps} from '@tarojs/components/types/ScrollView';

export default class CustomScrollView extends Component<
  ScrollViewProps & {
    // 自定义scrollTop
    scrollTopValue?: number;
  }
> {
  private scrollTop: number = 0;
  onScroll = (e: BaseEventOrig<ScrollViewProps.onScrollDetail>) => {
    this.scrollTop = e.detail.scrollTop;
    this.props.onScroll?.(e);
  };

  render() {
    const {children, scrollTopValue} = this.props;
    return (
      <ScrollView
        {...this.props}
        scrollTop={scrollTopValue ?? this.scrollTop}
        onScroll={this.onScroll}
        refresherDefaultStyle="none"
      >
        {children}
      </ScrollView>
    );
  }
}
